import app
from api.login_api import LoginApi

import requests

from config import Logger

log = Logger(app.base_dir + '/log/all.log', level='info')


class Staff_Api():
    def __init__(self):
        self.staff_url = "http://ihrm-test.itheima.net/api/sys/user"
        self.upload_url = "http://ihrm-test.itheima.net/api/sys/user/{}"
        self.query_url = "http://ihrm-test.itheima.net/api/sys/user/{}"
        self.delete_url = "http://ihrm-test.itheima.net/api/sys/user/{}"

    def staff_insert(self, staff_insert_data, headers):
        log.logger.info("添加的url={}".format(self.staff_url))
        return requests.post(self.staff_url, json=staff_insert_data, headers=headers)

    def upload_staff(self, url_params, headers, json_data):
        url = self.upload_url.format(url_params)
        log.logger.info("更新的url={}".format(url))

        return requests.put(url=url, json=json_data, headers=headers)

    def query_staff(self, url_param, headers):
        url = self.query_url.format(url_param)
        log.logger.info("查询的url={}".format(url))
        return requests.get(url=url, headers=headers)

    def delete_staff(self, url_param, headers):
        url = self.delete_url.format(url_param)
        log.logger.info("删除的url={}".format(url))
        return requests.delete(url=url, headers=headers)
